package com.geek.novel.adapter

import android.annotation.SuppressLint
import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.geek.novel.utils.LogCatUtil

open class BaseRecyclerViewHolder(itemView: View, val adapter: BaseRecyclerViewAdapter<BaseRecyclerViewHolder, Any>)
    : RecyclerView.ViewHolder(itemView) {

    var motionEvent: MotionEvent? = null

    @SuppressLint("ClickableViewAccessibility")
    open fun bind() {
        itemView.setOnTouchListener { v, event ->
            motionEvent = event
            false
        }
        //'为ItemView设置点击事件'
        itemView.setOnClickListener { view: View? ->
            if (adapter.onItemClickListener != null) {
                //需要处理倒序
                val position = adapterPosition
                //处理倒序
                val index: Int = adapter.getIndex(position)
                adapter.onItemClickListener!!.onItemClick(index, motionEvent)
            }
        }
        itemView.setOnLongClickListener {
            if(adapter.onItemLongClickListener != null){
                //需要处理倒序
                val position = adapterPosition
                //处理倒序
                val index: Int = adapter.getIndex(position)
                return@setOnLongClickListener adapter.onItemLongClickListener!!.onItemLongClick(index, motionEvent)
            }
            false
        }
    }

}